<?php

class Model_Form extends Zend_Form
{
    public $elementDecorators = array(
        'Label',
        'ViewHelper',
        'Errors',
        array('HtmlTag', array('tag' => 'div')),
    );

    public $fileDecorators = array(
        'Label',
        'File',
        'Errors',
        array('HtmlTag', array('tag' => 'div')),
    );

    public $buttonDecorators = array(
        'ViewHelper',
        array('HtmlTag', array('tag' => 'div', 'class' => 'button')),
    );

    public function init()
    {
        $this->addElementPrefixPath('App', Zend_Registry::get('config')
                                                ->paths
                                                ->library . '/App');
        $this->setDecorators(array(array(
            'ViewScript', array('viewScript' => 'form/default.phtml'))
        ));
    }

    protected function getEmail()
    {
        $user = new Model_User();
        $el = $this->createElement('text', 'email');
        $el
            ->setDecorators($this->elementDecorators)
            ->setLabel('Email:')
            ->setRequired(true)
            ->addFilter('StringToLower')
            ->addValidator('EmailAddress')
            ->addValidator('StringLength', false, array(1, 50))
            ->addValidator('DbUnique', true, array($user, 'email'));

        return $el;
    }

    protected function getSubmitButton()
    {
        return $this->createElement(
                'submit',
                'submit',
                array('decorators' => $this->buttonDecorators));
    }
}
